/*
 * Copyright 2010 Marcin Blazejewski
 *
 * This file is part of Nofate.
 *
 * Nofate is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Nofate is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Nofate. If not, see <http://www.gnu.org/licenses/>.
 *
 */


#include "thing.hpp"
#include "attribute.hpp"
#include "map.hpp"

#include <stdlib.h>
#include <string.h>

using namespace std;

Thing::Thing(const char *_name, char _alpha, char _ch, int _fg) :
    name(_name), alpha(_alpha), ch(_ch), fg(_fg) {

    type = TH_TYPE_THING;
}

Thing::~Thing() {
    map<string,Attr*>::iterator i;

    for (i = attributes.begin(); i != attributes.end(); i++) {
        delete i->second;
    }
}

/******************************************************************************/

Creature::Creature(const char *n, char _alpha, char _ch, int _fg) 
    : Thing(n, _alpha, _ch, _fg) {

    type = TH_TYPE_CREATURE;
    mv = NULL;

    init_container( EQS_HAND );
    init_container( EQS_HAND );
    init_container( EQS_PACK );
    init_container( EQS_ARMOUR );
}

Creature::~Creature() {
    vector<Thing*>::iterator i;
    delete mv;

    for (i = containers.begin(); i != containers.end(); i++) {
        delete *i;
    }
}

void Creature::init_container(int slot_id) {
    Thing *con_th;
    Attr *con_a;

    con_th = new Thing("_container_slot", 0, 0, 0);
    con_th->attributes["container"] = new Acontainer( slot_id, 0, 0 );
    containers.push_back( con_th );
} 

